package com.lsq.tucao.express.controller;

import com.lsq.tucao.express.bean.po.TucaoDetail;
import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.TucaoExpressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Author linshouqiang
* @Description 控制层
* @Date 2020/11/24 18:18
*/
@Slf4j
@RestController
@RequestMapping("/tucao")
public class TucaoExpressController {

    @Autowired
    private TucaoExpressService tucaoExpressService;

    /**
     * 发布吐槽
     * @param tucaoDetail
     * @return
     */
    @PostMapping
    public JsonResult addTucao(@RequestBody TucaoDetail tucaoDetail){
        log.debug("tucaoDetail:{}",tucaoDetail);
        return tucaoExpressService.addTucao(tucaoDetail);
    }

//    /**
//     * @author lsq
//     * @description 给吐槽点赞
//     * @param tucaoId 点赞的吐槽Id
//     * @return com.lsq.tucao.express.response.JsonResult
//     * @create 2021/4/20 22:16
//     */
//    @PutMapping("i-like")
//    public JsonResult likeTucao(@RequestParam Long tucaoId){
//        log.debug("tucaoId:{}",tucaoId);
//
//        return tucaoExpressService.likeTucao(tucaoId);
//    }

    /**
     * 分页展示吐槽
     * @param current 页码
     * @param size 每页条数
     * @param sort 吐槽类别
     * @param verify 是否审核；0表示未审核，1表示审核通过，2表示审核未通过
     * @param getVerified 获取已审核的数据
     * @return
     */
    @GetMapping("/page")
    public JsonResult page(@RequestParam(required = false,defaultValue = "1") Integer current,
                           @RequestParam(required = false,defaultValue = "10") Integer size,
                           @RequestParam(required = false) String sort,
                           @RequestParam(required = false) Integer verify,
                           @RequestParam(required = false,defaultValue = "false") Boolean getVerified){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("sort:{}",sort);
        log.debug("verify:{}",verify);
        log.debug("getVerified:{}",getVerified);

        return tucaoExpressService.getPageTucao(current, size, sort, verify, getVerified);
    }

    /**
     * @author lsq
     * @description 根据id查询吐槽数据
     * @param tucaoId id
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/16 11:59
     */
    @GetMapping("/one")
    public JsonResult getTucaoById(@RequestParam Long tucaoId){
        log.debug("tucaoId:{}",tucaoId);

        return tucaoExpressService.getTucaoById(tucaoId);
    }

    /**
     * @author lsq
     * @description 审核吐槽数据
     * @param tucaoId id
     * @param verify true：审核通过；false：审核未通过
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/16 12:34
     */
    @PutMapping("/verify")
    public JsonResult verifyTucao(@RequestParam Long tucaoId,
                                  @RequestParam Boolean verify){
        log.debug("tucaoId:{}",tucaoId);
        log.debug("verify:{}",verify);

        return tucaoExpressService.verifyTucao(tucaoId, verify);
    }

    /**
     * @author htt
     * @description 根据用户搜索吐槽
     * @param current 页码
     * @param size 每页条数
     * @param username 用户名
     * @param sort 吐槽类别
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 19:49
     */
    @GetMapping("/search-by-username")
    public JsonResult searchTucaoByUsername(@RequestParam(required = false,defaultValue = "1") Integer current,
                                            @RequestParam(required = false,defaultValue = "10") Integer size,
                                            @RequestParam String username,
                                            @RequestParam String sort){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("username:{}",username);
        log.debug("sort:{}",username);

        return tucaoExpressService.searchTucaoByUsername(current,size,username,sort);
    }

    /**
     * @author htt
     * @description 根据吐槽内容搜索当前吐槽类别下的吐槽数据
     * @param current 页码
     * @param size 每页条数
     * @param content 吐槽内容
     * @param sort 吐槽类别
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 19:50
     */
    @GetMapping("/search-by-content")
    public JsonResult searchTucaoByContent(@RequestParam(required = false,defaultValue = "1") Integer current,
                                           @RequestParam(required = false,defaultValue = "10") Integer size,
                                           @RequestParam String content,
                                           @RequestParam String sort){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("content:{}",content);
        log.debug("sort:{}",sort);

        return tucaoExpressService.searchTucaoByContent(current,size,content,sort);
    }

    /**
     * @author lsq
     * @description 排序吐槽数据
     * @param current 页码
     * @param size 每页条数
     * @param sortBy 排序依据
     * @param sort 吐槽类别
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 19:51
     */
    @GetMapping("/sort")
    public JsonResult sortTucaoBy(@RequestParam(required = false,defaultValue = "1") Integer current,
                                  @RequestParam(required = false,defaultValue = "10") Integer size,
                                  @RequestParam String sortBy,
                                  @RequestParam String sort){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("sortBy:{}",sortBy);
        log.debug("sort:{}",sort);

        return tucaoExpressService.sortTucaoBy(current,size,sortBy,sort);
    }


}
